import { Injectable } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { environment } from '@env/environment';
import { map } from 'rxjs/operators';
import { Cache } from '../../../../shared/utils/cache';

@Injectable({
	providedIn: 'root',
})
export class AuthDictService {

	tallyUserList = [];
	dictLocationInfo = {};
	dictLocationInfoList = [];
	dictMainLocationInfo = {};
	dictMainLocationInfoList = [];
	constructor(private httpClient: _HttpClient, private cache: Cache) {}

	dictionary(code: any, isBiz?) {
		if (isBiz) {
			return this.dictionaryBiz(code);
		} else {
			return this.dictionarySys(code);
		}
	}

	dictionarySys(code: any) {
		return this.cache.get('blade-system/dict/dictionary', { code }).pipe(
			map((item) => {
				item.sort((a, b) => {
					return a.sort - b.sort;
				});
				return item;
			})
		);
	}

	dictionaryBiz(code: any, subsystemCode = environment.subsystem.code) {
		return this.cache.get('blade-system/dict-biz/dictionary', { subsystemCode, code }).pipe(
			map((item) => {
				item.sort((a, b) => {
					return a.sort - b.sort;
				});
				return item;
			})
		);;
	}

	dictionaryB(code: any): any {
		return this.httpClient.get('blade-system/dict-biz/dictionary', code).pipe(
			map((item: any[]) => {
				item.sort((a, b) => {
					return a.sort - b.sort;
				});
				return item;
			})
		);
	}
}
